﻿using Config;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IYAKASAPortal.Dispatch
{
    public partial class DispatchList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                btnSearchALL_Click(sender, e);
            }
        }



        private void SelectSql(string Sql)
        {
            string strKeywords = txtKeywords.Text;
            string strSql = "select ID,HPHM,HPZL,JYLB,JCZT_STATUS = case when JCZT_STATUS=0 then  '等待未检' when JCZT_STATUS=1 then '车辆上线' when JCZT_STATUS=2 then '正在检测' when JCZT_STATUS=3 then '等待下线' when JCZT_STATUS=4 then '车辆下线' end  from VEHICLE_DISPATCH where JYLBDH like " + Sql + "  ";

            if (strKeywords.Length > 0)
            {
                strSql += "and ";
                strSql += "(HPHM like '%" + strKeywords + "%'";
                strSql += "or HPZL like '%" + strKeywords + "%')";
            }

            strSql += " order by ID desc";

            DataTable m_dtTable = new DataTable();
            GreatPager1.BindDataTablePage(ref m_dtTable, AppConfig.g_strConnectionStringSqlClient, strSql, 20);
            rptList.DataSource = m_dtTable;
            rptList.DataBind();
            m_dtTable.Dispose();


        }

        protected void btnSearchALL_Click(object sender, EventArgs e)
        {
            DropDownListSelect.SelectedIndex = 0;
            txtKeywords.Text = "";
            this.SelectSql("'%'");
        }

        protected void GreatPager1_PageIndexChanging(object sender, gfPage.PagerEventArgs e)
        {
            GreatPager1.PageIndex = e.NewPageIndex;

            DataTable m_dtTable = GreatPager1.BindDataTablePage();
            rptList.DataSource = m_dtTable;
            rptList.DataBind();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (DropDownListSelect.SelectedValue == "安检")
            {
                this.SelectSql("'%0_,%'");
            }
            if (DropDownListSelect.SelectedValue == "综检")
            {
                this.SelectSql("'%1_,%'");
            }
            if (DropDownListSelect.SelectedValue == "环保")
            {
                this.SelectSql("'%2_,%' or JYLBDH like '%X_,%' ");

            }
            if (DropDownListSelect.SelectedValue == "全部")
            {
                this.SelectSql("'%'");
            }
        }

        protected void DropDownListSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DropDownListSelect.SelectedValue == "安检")
            {
                this.SelectSql("'%0_,%'");
            }
            if (DropDownListSelect.SelectedValue == "综检")
            {
                this.SelectSql("'%1_,%'");
            }
            if (DropDownListSelect.SelectedValue == "环保")
            {
                this.SelectSql("'%2_,%' or JYLBDH like '%X_,%' ");

            }
            if (DropDownListSelect.SelectedValue == "全部")
            {
                this.SelectSql("'%'");
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {

        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {

        }
    }
}